import math
import itertools, functools
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import math
from decimal import Decimal

mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42
mpl.rcParams['axes.linewidth'] = 1.5
mpl.rcParams['lines.linewidth'] = 3
mpl.rcParams['lines.markersize'] = 10
mpl.rcParams['font.size'] = 15
mpl.rcParams['xtick.labelsize'] = 14
mpl.rcParams['ytick.labelsize'] = 16
mpl.rcParams['legend.fontsize'] = 14
mpl.rcParams['legend.framealpha'] = 0
mpl.rcParams['legend.borderpad'] = 0.1
mpl.rcParams["axes.labelweight"] = "bold"
mpl.rcParams["axes.labelsize"] = 14
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['figure.figsize'] = (7.5, 4.3)

sns.set_style("darkgrid")

def plot(type):
    if type == 'dr':
      df = pd.read_csv('dr.csv')
    else:
      df = pd.read_csv('sr.csv')
      
        
    g = sns.boxplot(data=df, x='numJob', y='time', hue='sys', linewidth=1)
    # g = sns.boxplot(data=df, y='Dataset', x='#LEAP/#GAP', hue='aptype', orient='h', linewidth=2)
    hatches = ['/', '\\\\', 'o']
    # Add annotations and hatches
    ax = g.axes
        
    legend = ax.get_legend()
    legend.set_title('')
    plt.legend(ncol=4, loc="upper right")
    
    # plt.legend(loc=[0.75, 0.25])
    # plt.legend().remove()
    plt.xlabel('#Scheduled job', weight='bold')
    # plt.xticks(fontsize=12, rotation=0)
    plt.ylabel('Time (s)', weight='bold')
    plt.ylim(30, 160)
    plt.tight_layout(pad=1.1)
    plt.savefig(type + '.pdf', bbox_inches='tight')
    # plt.show()
    plt.close()
    
    avg_de = df[df.sys=='DE-BFO'].mean()
    compared = [
      df[df.sys=='FCFS'].mean(),
      df[df.sys=='PSO'].mean(),
      df[df.sys=='EPSO'].mean(),
    ]
    
    print([avg_de/ i for i in compared])

def plotsche():
    df = pd.read_csv('sche.csv')
        
    g = sns.boxplot(data=df, x='numJob', y='time', hue='type', linewidth=1)
    # g = sns.boxplot(data=df, y='Dataset', x='#LEAP/#GAP', hue='aptype', orient='h', linewidth=2)
    hatches = ['/', '\\\\', 'o']
    # Add annotations and hatches
    ax = g.axes
        
    legend = ax.get_legend()
    legend.set_title('')
    plt.legend(ncol=4, loc="upper right")
    
    # plt.legend(loc=[0.75, 0.25])
    # plt.legend().remove()
    plt.xlabel('#Scheduled job', weight='bold')
    # plt.xticks(fontsize=12, rotation=0)
    plt.ylabel('Time (s)', weight='bold')
    plt.ylim(30, 120)
    plt.tight_layout(pad=1.1)
    plt.savefig('sche.pdf', bbox_inches='tight')
    # plt.show()
    plt.close()
    print(df[df.type=='SSRV'].mean()/df[df.type=='DSRV'].mean())

plot('dr')
plot('sr')
plotsche()